const { getDependencies } = require('./pack-base')
const Metro = require('metro');
const argv = process.argv;
const platform = argv[2] || 'ios';
const { file } = require('utils');
async function run() {
  const config = await Metro.loadConfig({
    maxWorkers: 1,
    // config: './metro-get-deps.config.js',
  });
  // await Metro.runBuild(config, {
  //   entry: 'index.js',
  //   out: `bundle-${platform}/bundle.js`,
  //   platform: platform,
  //   // minify: false,
  //   // dev: true,
  // });
  const deps = await getDependencies(config, {
    entry: 'index.js',
    out: `bundle-${platform}/bundle.js`,
    platform: platform,
    minify: true,
    dev: false,
  })
  const result = deps.filter(ele => {

    const item = [
      "node_modules/react-native/",
      "node_modules/react/",
      "node_modules/promise/",
      "node_modules/@babel/",
      "node_modules/invariant/",
      "node_modules/fbjs/",
      "node_modules/prop-types/",
      "node_modules/object-assign/",
      "node_modules/stacktrace-parser/",
      "node_modules/regenerator-runtime/",
      "node_modules/event-target-shim/",
      "node_modules/base64-js/",
      "node_modules/whatwg-fetch/",
      "node_modules/abort-controller/",
      "node_modules/scheduler/",
      "node_modules/art/",
      "node_modules/nullthrows/",
      "node_modules/create-react-class/",
      "node_modules/metro/",
      
      // 其他依賴
      // "node_modules/moment",
      // "node_modules/lodash",
      // "node_modules/react-native-vector-icons",
      // "node_modules/react-native-animatable",
      // "node_modules/async-validator",
      // "node_modules/@react-native-community",
      // "node_modules/react-native-modal/",
      // "src/",
      // "require-index.js",
      "__prelude__"
    ].find(e => ele.startsWith(e))
    return !!item
  })
  file.writeFile(`./dependencies-${platform}.json`, JSON.stringify(result))
  // console.log(deps.length)
  // console.log(result.length)

}

run();
